import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 * 不需要权限就可以访问
 */
export const constantRoutes = [
    {
      path: '*',
      redirect: '/'
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/home/index'),
        name: 'Home',
        meta: { title: '首页', icon: 'el-icon-s-home', affix: true }
      }
    ]
  },
  {
    path: '/account',
    component: Layout,
    redirect:'/account/userCard',
    name: 'AccountCenter',
    meta: {
      title: '个人中心',
      icon: 'el-icon-user-solid',
    },
    children: [
      {
        path: '/account/userCard',
        component: () => import('@/views/account/index'),
        name: 'userCard',
        meta: { title: '个人信息',icon: 'el-icon-user'}
      },
      {
        path: '/account/accountSafe',
        component: () => import('@/views/account/index'),
        name: 'accountSafe',
        meta: { title: '安全中心',icon: 'el-icon-wallet'}
      },
      {
        path: '/account/myOrder',
        component: () => import('@/views/account/index'),
        name: 'myOrder',
        meta: { title: '个人订单',icon:'el-icon-s-claim'}
      },
      {
        path: '/account/help',
        component: () => import('@/views/account/index'),
        name: 'help',
        meta: { title: '问题反馈',icon:'el-icon-question'}
      },
    ]
  },
  {
    path: '/fieldcenter',
    component: Layout,
    redirect: '/field/fieldList',
    name: 'Field',
    meta: {
      title: '场馆中心',
      icon: 'el-icon-office-building'
    },
    children: [
      {
        path: '/field/fieldList',
        component: () => import('@/views/field/FieldList'),
        name: 'FieldList',
        meta: { title: '运动场馆',icon: 'el-icon-school' }
      },
      {
        path: '/account/myBook',
        component: () => import('@/views/account/index'),
        name: 'myBook',
        meta: { title: '个人预约',icon: 'el-icon-date' },
      },
      {
        path: '/field/fieldbook/:pid(\\d+)/:name',
        component: () => import('@/views/field/FieldBook'),
        name: 'FieldBook',
        meta: { title: '预约场馆',icon: 'el-icon-school',noCache:true,activeMenu:'/field/fieldList' },
        hidden: true
      },
    ]
  },
  {
    path: '/equipment/center',
    component: Layout,
    redirect: '/equipment/equipmentList',
    name: 'Equipment',
    meta: {
      title: '器材中心',
      icon: 'el-icon-s-cooperation'
    },
    children: [
      {
        path: '/equipment/equipmentList',
        component: () => import('@/views/equipment/EquipmentList'),
        name: 'EquipmentList',
        meta: { title: '运动器材',icon: 'el-icon-basketball' }
      },
      {
        path: '/account/myRent',
        component: () => import('@/views/account/index'),
        name: 'myRent',
        meta: { title: '个人租借',icon: 'el-icon-shopping-bag-1' },
      },
    ]
  },
  {
    path: '/notice',
    component: Layout,
    redirect: '/notice/list',
    name: 'Notice',
    hidden: true,
    meta: {
      title: '公告',
      icon: 'el-icon-s-cooperation'
    },
    children: [
      {
        path: '/notice/list',
        component: () => import('@/views/msg/NoticeList'),
        name: 'NoticeList',
        meta: { title: '公告列表',icon: 'el-icon-document' },
        hidden: true
      },
      {
        path: '/noticeinfo/:type/:no',
        component: () => import('@/views/msg/NoticeInfo'),
        name: 'NoticeInfo',
        meta: { title: '公告详情',noCache:true,activeMenu:'/notice/list' },
        hidden: true
      },
    ]
  },
]

const createRouter = () => new Router({
  // require service support
  //默认hash模式
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
